package com.example.controller;


import com.example.common.result.Result;
import com.example.entity.dto.SalaryDto;

import com.example.entity.vo.WageVO;
import com.example.service.SalaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Date;
import java.util.List;

@RestController
@RequestMapping("/wage")
@Api(tags = "工资表接口")
@Slf4j
public class WageController {
    @Autowired
    private SalaryService salaryService;
    /**
     *
     * @param  salaryDto
     * @return
     */
    @PostMapping("/savesalary")
    @ApiOperation("计算保存员工工资")
    public Result savesalary(@RequestBody SalaryDto salaryDto){
        log.info("计算保存员工工资：{}",salaryDto);
        salaryService.savesalary(salaryDto);
        return Result.success();
    }

    /**
     * 获取员工工资信息
     * @param id
     * @param date
     * @return
     */
    @GetMapping("/get")
    @ApiOperation("获取员工工资信息")
    public Result<WageVO> getSalary(@RequestParam int id, @RequestParam String date){
        log.info("获取员工工资信息：{},{}",id,date);
        WageVO wageVO = salaryService.getsalary(id,date);
        if(wageVO.getEmployeeId() == null){
            salaryService.save(id,date);
            wageVO = salaryService.getsalary(id,date);
        }
        salaryService.update(wageVO);
        return Result.success(wageVO);
    }

    /**
     * 修改员工工资
     * @param wageVO
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("修改员工工资")
    public Result update(@RequestBody WageVO wageVO){
        log.info("修改员工工资:{}",wageVO);
        salaryService.update(wageVO);
        return Result.success();
    }
}
